import 'package:flutter/material.dart';
import 'package:fantuike_app/constants.dart' show Constants;
import 'index_page.dart';
import 'person_page.dart';
import 'find_page.dart';
import 'store_page.dart';
import 'activity_page.dart';

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  int _currentIndex = 0;

  List<BottomNavigationBarItem> _navigationItemList = [
    BottomNavigationBarItem(
        icon: Icon(IconData(0xe603, fontFamily: Constants.IconFontFamily)),
        title: Text("首页")),
    BottomNavigationBarItem(
        icon: Icon(IconData(0xe655, fontFamily: Constants.IconFontFamily)),
        title: Text("购物")),
    BottomNavigationBarItem(
        icon: Icon(IconData(0xe746, fontFamily: Constants.IconFontFamily)),
        title: Text("发现")),
    BottomNavigationBarItem(
        icon: Icon(
          IconData(0xe612, fontFamily: Constants.IconFontFamily),
        ),
        title: Text("活动")),
    BottomNavigationBarItem(
        icon: Icon(IconData(0xe7ab, fontFamily: Constants.IconFontFamily)),
        title: Text("我的"))
  ];
  List<Widget> _pages = [
    IndexPage(),
    StorePage(),
    FindPage(),
    ActivityPage(),
    PersonPage()
  ];
  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController(initialPage: _currentIndex);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: _navigationItemList,
        fixedColor: Colors.redAccent,
        type: BottomNavigationBarType.fixed,
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
            _pageController.jumpToPage(_currentIndex);
          });
        },
        currentIndex: _currentIndex,
      ),
      body: PageView.builder(
        itemBuilder: (BuildContext context, int index) {
          return _pages[index];
        },
        controller: _pageController,
        itemCount: _pages.length,
        onPageChanged: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
        physics: NeverScrollableScrollPhysics(),
      ),
    );
  }
}
